// prac keep 1
package util;

import org.testng.annotations.Test;
import org.openqa.jetty.http.HttpRequest;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;

import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;

import java.io.File;
import org.w3c.dom.*;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.testng.annotations.Test;

public class readelementsxml
{
		@Test

	   public void readall_printxml() 
		{
		  
		  try {
		

			  
			  DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
			  DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
			 // Document doc = docBuilder.parse (new File("D:\\09012015\\Desktop\\xml1.xml")); // normalize text representation
			  Document doc = docBuilder.parse ("http://zissit2wb01.education.vic.gov.au:8082/ZIServerAdmin/XMLMessage.aspx?RecordID=378867&MessageType=AUDITMESSAGE");
			  doc.getDocumentElement ().normalize ();
			 // System.out.println ("Root element of the doc is " + doc.getDocumentElement().getNodeName());
			  
			  NodeList searchnode= doc.getElementsByTagName("SIF_EventObject").item(0).getChildNodes();
			  
			  System.out.println(" nodes count :" + searchnode.getLength());
			  
			  recurs( searchnode);
			 }

		  catch (SAXParseException err) 
		  {
			  System.out.println (" ** Parsing error" + ", line " + err.getLineNumber () + ", uri " + err.getSystemId ());
			  System.out.println("  "   + err.getMessage ());
		  }

			  catch (SAXException e)
			  {
			  Exception x = e.getException ();
			  ((x == null) ? e : x).printStackTrace (); 
			  }
		  
			  	catch (Exception e)
			  		{
			  			e.printStackTrace();
			  		}
		  	  
		  

		}
  
   public void recurs(NodeList searchnode)
   {
	 try 
	 {
		 if (searchnode.getLength()>=0)
		   {
			   
			 System.out.println("length of nodelist " +searchnode.toString()+ "  : "+ searchnode.getLength());
			  for(int i=0; i<searchnode.getLength(); i++)
			   {
			   Node child = searchnode.item(i);
				   	  
		
				   
				   System.out.println( i + " of type "+child.getNodeType()+ " whose name is "+child.getNodeName()+  " value is "+ child.getNodeValue()  );
			  //Node child = searchnode.item(0);
			 // System.out.println( "whose name is "+child.getNodeName()+  " value is "+ child.getNodeValue());
			 
			 
				   	if (child.getChildNodes().getLength()>=0)
				   	{
				   		NodeList searchnode1=child.getChildNodes();
				   		recurs(searchnode1);
				   	}
	        
			  }
		   }
	 }

		  
			  	catch (Exception e1)
			  		{
			  			e1.printStackTrace();
			  		}
		  	  
   
   }
   
}








